<?php
/**
 * Created by PhpStorm.
 * User: EZ
 * Date: 2017/5/22
 * Time: 17:38
 */

class ClassOne {
    function callClassOne($a,$b) {

      echo "我被调用了，参数:$a---$b";
    }
}
class ClassOneDelegator {
    private $targets;
    function addObject($obj) {
        $this->target[] = $obj;
    }
    function __call($name, $arg) {
        var_dump($arg);
        echo '调用了一个不存在的方法:'.$name.';参数:55'.'<br />';
        foreach ($this->target as $obj) {
            $r = new ReflectionClass($obj);
            if ($method = $r->getMethod($name)) {
                if ($method->isPublic() && !$method->isAbstract()) {
                    if(is_array($arg) && count($arg)>0){
                        $arg_str=join(",",$arg);
//                        echo $arg_str;die;
                        $method->invoke($obj,$arg_str);
                    }else{
                        $method->invoke($obj);
                    }
//                    $method->invoke($obj,$arg[0],$arg[1]);
                }
            }
        }
    }
}
$obj = new ClassOneDelegator();
$obj->addObject(new ClassOne());
$obj->callClassOne('zhaodaw','23');